package edu.towson.cis.cosc490.shill10.lab3;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

public class ToDoListActivity extends Activity implements OnClickListener, OnLongClickListener {
	
	Button m_addButton;
	EditText m_editText;
	LinearLayout m_itemListView;
	boolean darkBack = false;
	
	public void initLayout() {
		m_addButton = (Button) this.findViewById(R.id.button1);
		m_editText = (EditText) this.findViewById(R.id.editText1);
		m_itemListView = (LinearLayout) this.findViewById(R.id.toDoListView);
	}

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        initLayout();
        m_addButton.setOnClickListener(this);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_to_do_list, menu);
        return true;
    }
    
    public void onClick(View v) {
    	String newString = m_editText.getText().toString();
    	ToDoItem addToList = new ToDoItem(newString);
    	TextView newItemTextView = new TextView(this);
    	if(darkBack == false) {
    		newItemTextView.setBackgroundColor(getResources().getColor(R.color.dark));
    		darkBack = true;
    	}
    	else {
    		newItemTextView.setBackgroundColor(getResources().getColor(R.color.light));
    		darkBack = false;
    	}
    	newItemTextView.setOnLongClickListener(this);
    	newItemTextView.setText(addToList.getToDoItem());
    	m_itemListView.addView(newItemTextView);
    	m_editText.setText("");
    }
    
    public boolean onLongClick(View v) {
    	TextView tv = (TextView) v;
    	String message = tv.getText().toString();
    	
    	Intent smsIntent = new Intent(Intent.ACTION_VIEW);
    	
    	smsIntent.putExtra("sms_body", "To-Do List Item: " + message);
    	smsIntent.putExtra("address", "");
    	smsIntent.setType("vnd.android-dir/mms-sms");
    	
    	startActivity(smsIntent);
    	
    	return false;
    }

}
